put Today into field "LastDate" of card "Title Card" -- store the date away
put word 1 of item 2 of Today into Month
if Month is in "May, June, July, August, September" then
put "DST" into DSTSeason -- it's summer, turn on DST
exit DateChanged
else
if Month is in "November, December, January, February, March" then
put "NoDST" into DSTSeason -- it's winter, no DST
exit DateChanged
end if
end if
-- if we get this far, it is either April or October,
-- need to check in more detail
put item 1 of Today into Day
put word 2 of item 2 of Today into Date
if Month = "April" then
if Date > 7 then -- after the switch to DST
put "DST" into DSTSeason
exit DateChanged
else
-- we're in the first week of April. Find out how many days
-- until the next Sunday
put DayToNum(Day) into DaysTilSunday
if DaysTilSunday = 0 then -- Today is Sunday! DST in effect
put "DST" into DSTSeason
exit DateChanged
else -- Figure out how many days left 'til the 7th
put 7 - Date into DaysLeft
if DaysLeft < DaysTilSunday then -- must be past the first Sunday
put "DST" into DSTSeason
else -- we are before the change
put "NoDST" into DSTSeason
end if
exit DateChanged
end if
end if
end if -- End of April clause
--
-- if we get this far, it is October
--
if Date < 25 then -- before the switch to NoDST
put "DST" into DSTSeason
exit DateChanged
else
-- we're in the last week of October. Find out how many days
-- until the next Sunday
put DayToNum(Day) into DaysTilSunday
if DaysTilSunday = 0 then -- Today is Sunday! NoDST in effect
put "NoDST" into DSTSeason
exit DateChanged
else -- Figure out how many days left 'til the 31st
put 31 - Date into DaysLeft
if DaysLeft < DaysTilSunday then -- must be past the last Sunday
put "NoDST" into DSTSeason
else -- we are before the change
put "DST" into DSTSeason
end if
exit DateChanged
end if
end if
put DSTSeason
end DateChanged
-- This function converts the day of the week into
-- the number of days until Sunday
function DayToNum theDay
if theDay = "Monday" then return 6
if theDay = "Tuesday" then return 5
if theDay = "Wednesday" then return 4
if theDay = "Thursday" then return 3
if theDay = "Friday" then return 2
if theDay = "Saturday" then return 1
if theDay = "Sunday" then return 0
end DayToNum
-- This function is called when the user's Area Code
-- changes. It sets the Hidden fields "GMTHere" and "DSTObservedHere"
-- on the Title card
function AreaCodeChanged NewCode
set lockScreen to true
go to first card of bg "Main"
find word NewCode in field "Area/City Code"
if the result is empty then -- successful search
put field "GMTThere" into field "GMTHere" of card "Title Card"
put GetDSTObserved(bg field "Country Code", bg field "Area/City Code") into bg field "DSTObservedHere" of card "Title Card"
put true into rslt
else
put false into rslt
end if
go back
go back
set lockScreen to false
return rslt
end AreaCodeChanged
function GetDSTObserved CountryCode, AreaCode
-- if we are in the US or Canada, use area code to decide.
if CountryCode is "1" then
if AreaCode is in "602,317,219,808,809" then
put "NoDST" into rslt
else
put "DST" into rslt
end if
else -- we are in another country, so use country code to decide.
-- if the country code of this card is NOT in the list of
-- country codes that DO observe DST, then put "NoDST"...
if CountryCode is not in "1,7,20,21,31,32,33,33,34,36,37,38,39,40,41"& "42,43,44,45,46,47,48,49,63,86,90,216,298"& "299,350,351,352,353,355,356,357,358,359,508"& "509,809,809,962,963,964,972" then